<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pvscent</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pvscale.html" title="pvscale" />
    <link rel="next" href="pvscross.html" title="pvscross" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pvscent</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pvscale.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pvscross.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pvscent"></a>
      <div class="titlepage"></div>
      <a id="IndexPvscent" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pvscent</span>
        </h2>
        <p>pvscent — 
      Calculate the spectral centroid of a signal.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138283696"></a>
        <h2>Description</h2>
        <p>
      Calculate the spectral centroid of a signal from its discrete Fourier transform.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138284960"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">kcent <span class="command"><strong>pvscent</strong></span> fsig</pre>
      </div>
      <div class="refsect1">
        <a id="idp138287104"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kcent</em></span> -- the spectral centroid
    </p>
        <p>
      <span class="emphasis"><em>fsig</em></span> -- an input pv stream
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138289600"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the use of the <span class="emphasis"><em>pvscent</em></span> opcode. It uses the file <a class="ulink" href="examples/pvscent.csd" target="_top"><em class="citetitle">pvscent.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp138291904"></a>
          <p class="title">
            <strong>Example 682. Example of the <span class="emphasis"><em>pvscent</em></span> opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-odac
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 16
<span class="ohdr">nchnls</span> <span class="op">=</span> 1
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="comment">;; example written by joachim heintz 2009</span>

giSine		<span class="ohdr">ftgen</span>		0, 0, 4096, 10, 1

<span class="oblock">instr</span> 1
irefrtm	<span class="op">=</span>		p4<span class="comment">; time for generating new values for the spectral centroid</span>
ifftsize	<span class="op">=</span>		1024
ioverlap	<span class="op">=</span>		ifftsize <span class="op">/</span> 4
iwinsize	<span class="op">=</span>		ifftsize
iwinshape	<span class="op">=</span>		1<span class="comment">; von-Hann window</span>
<span class="comment">;Sfile		=		"flute-C-octave0.wav"</span>
Sfile		<span class="op">=</span>		"fox.wav"
ain		<span class="opc">soundin</span>	Sfile
fftin		<span class="opc">pvsanal</span>	ain, ifftsize, ioverlap, iwinsize, iwinshape<span class="comment">; fft-analysis of the audio-signal</span>
ktrig		<span class="opc">metro</span>		1 <span class="op">/</span> irefrtm
<span class="octrl">if</span> ktrig <span class="op">==</span> 1 then
kcenter	<span class="opc">pvscent</span>	fftin<span class="comment">; spectral center</span>
<span class="octrl">endif</span>
aout		<span class="opc">oscil</span>		.2, kcenter, giSine
		<span class="opc">out</span>		aout
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 2.757 .3
<span class="stamnt">i</span> 1 3 2.757 .05
<span class="stamnt">i</span> 1 6 2.757 .005
<span class="stamnt">i</span> 1 9 2.757 .001
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138296624"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="pvsanal.html" title="pvsanal"><em class="citetitle">pvsanal</em></a>,
      <a class="link" href="pvsynth.html" title="pvsynth"><em class="citetitle">pvsynth</em></a>,
      <a class="link" href="pvsadsyn.html" title="pvsadsyn"><em class="citetitle">pvsadsyn</em></a>,
      <a class="link" href="pvspitch.html" title="pvspitch"><em class="citetitle">pvspitch</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138301728"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch;</td>
          </tr>
          <tr>
            <td>March 2005</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New plugin in version 5</p>
        <p>March 2005.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pvscale.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pvscross.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pvscale </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pvscross</td>
        </tr>
      </table>
    </div>
  </body>
</html>
